﻿<!DOCTYPE html>
<html>
<head>
<title>XDate - A Modern JavaScript Date Library</title>
<link href='http://fonts.googleapis.com/css?family=Ubuntu' rel='stylesheet' type='text/css'>
<link rel='stylesheet' type='text/css' href='main.css' />
<link rel='stylesheet' type='text/css' href='syntax.css' />
<script>
// google analytics
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-3534877-5']);
_gaq.push(['_trackPageview']);
(function() {
	var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
	ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
	var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
function trackDownload(url) {
	_gaq.push(['_trackPageview', url]);
}
</script>
</head>
<body>

<div id='nav'>
<ul>
<li><a href='#Introduction'>Introduction</a></li>

<li><a href='#Constructors'>Constructors</a></li>
<li><a href='#Getters'>Getters</a></li>
<li><a href='#Setters'>Setters</a></li>
<li><a href='#Adding'>Adding</a></li>
<li><a href='#Diffing'>Diffing</a></li>
<li><a href='#Parsing'>Parsing</a></li>
<li><a href='#Formatting'>Formatting</a></li>
<li><a href='#UTC_Methods'>UTC Methods</a></li>
<li><a href='#UTC_Mode'>UTC Mode</a></li>

<li><a href='#Utilities'>Utilities</a></li>
<li><a href='#Chaining'>Chaining</a></li>
<li><a href='#Inconsistencies'>Inconsistencies</a></li>
<li><a href='#Deprecated'>Deprecated</a></li>
</ul>
</div>

<div id='main'>

<h1 id='Introduction'><span>X</span>Date</h1>
<div id='slogan'>A Modern JavaScript Date Library</div>

<p>
XDate is a thin wrapper around JavaScript's native <a href='https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Date'>Date</a>
object that provides enhanced functionality for parsing, formatting, and manipulating dates. It implements the same methods as the native Date,
so it should seem very familiar.
</p>

<p>
Also, it is non-destructive to the DOM, so it can safely be included in third party libraries without fear
of side effects.
</p>

<div id='download-area'>
<div id='download-area-left'>
<div class='label'>Download:</div>
<div class='link'>

<a href='/xdate/downloads/0.5/xdate.js'
   onclick="trackDownload('/xdate/downloads/0.5/xdate.js')">
xdate.js
</a>
</div>
</div>
<div id='download-area-right'>
<div>Size: 6.9k (2.9 gzipped)</div>
<div>Version: 0.5</div>
<div>Released: Oct 24th, 2011</div>
<div>
<a href='/xdate/downloads/0.5/xdate.dev.js'
   onclick="trackDownload('/xdate/downloads/0.5/xdate.dev.js')">
Development Version
</a>
</div>

</div>
<div style='clear:left'></div>
</div>

<div>
</div>
</div>

<div style='clear:both'></div>



<h2 id="Constructors">Constructors</h2>



<dl><dt>
    new XDate()
</dt>
<dd>
    Creates a new XDate with the current date and time
</dd>
<dt>
    new XDate(xdate)
</dt>
<dd>
    Creates a copy of the given XDate
</dd>

<dt>
    new XDate(nativeDate)
</dt>
<dd>
    Creates a new XDate from a native
    <a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Date">Date</a>
</dd>
<dt>
    new XDate(milliseconds)
</dt>
<dd>
    Creates a new XDate that is <code>milliseconds</code> since the UTC epoch.

</dd>
<dt>
    new XDate(year, month, <i>date, hours, minutes, seconds, milliseconds</i>)
</dt>
<dd>
    Creates a new XDate from the given values.
</dd>
<dt>
    new XDate(dateString)
</dt>
<dd>
    Read more about date-string <a href="#Parsing">parsing</a>

</dd>
</dl><p>With all the constructors, a final <code>utcMode</code> parameter can be appended as the last argument.
If <code>true</code>, the XDate will be in <a href="#UTC_Mode">UTC&#xA0;Mode</a>.</p>

<p>The constuctors can be called without the <code>new</code> operator, as a function.</p>

<h2 id="Getters">Getters</h2>




<dl><dt>
    .getFullYear()</dt>
<dd>
    Returns the 4-digit year
</dd>
<dt>
    .getMonth()

</dt>
<dd>
    Value is zero-index, meaning Jan=0, Feb=1, Mar=2, etc.
</dd>
<dt>
    .getWeek()
</dt>
<dd>
    Returns the ISO week of the year
</dd>
<dt>
    .getDate()
</dt>

<dd>
    Returns the date of the month
</dd>
<dt>
    .getDay()
</dt>
<dd>
    Returns the day-of-week as a number. Sun=0, Mon=1, Tue=2, etc.
</dd>
<dt>
    .getHours()
</dt>
<dt>

    .getMinutes()
</dt>
<dt>
    .getSeconds()
</dt>
<dt>
    .getMilliseconds()
</dt>
<dt>
    .getTime()
</dt>
<dd>
    Milliseconds since the epoch.

</dd>
<dt>
    .valueOf()
</dt>
<dd>
    Milliseconds since the epoch. Identical to <code>getTime</code>.
</dd>
</dl><h2 id="Setters">Setters</h2>




<dl><dt>
    .setFullYear(year, <i>preventOverflow</i>)
</dt>
<dd>
    <code>year</code> is a 4-digit year
</dd>
<dt>
    .setMonth(month, <i>preventOverflow</i>)

</dt>
<dd>
    <code>month</code> is zero-indexed, meaning Jan=0, Feb=1, Mar=2, etc.
</dd>
<dt>
    .setDate(date)
</dt>
<dd>
    Set the date of the month
</dd>
<dt>
    .setHours(hours)

</dt>
<dt>
    .setMinutes(minutes)
</dt>
<dt>
    .setSeconds(seconds)
</dt>
<dt>
    .setMilliseconds(milliseconds)
</dt>
<dd>
    Milliseconds since the epoch
</dd>

<dt>
    .setTime(milliseconds)
</dt>
<dd>
    Milliseconds since the epoch. Identical to <code>setMilliseconds</code>.
</dd>
</dl><p>Setting <code>preventOverflow</code> to <code>true</code> prevents a date from "overflowing" into the next month.
Example:</p>

<div class="highlight"><pre><span class="nx">d</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">XDate</span><span class="p">(</span><span class="mi">2011</span><span class="p">,</span> <span class="mi">7</span><span class="p">,</span> <span class="mi">31</span><span class="p">);</span> <span class="c1">// August 31</span>

<span class="nx">d</span><span class="p">.</span><span class="nx">setMonth</span><span class="p">(</span><span class="mi">8</span><span class="p">);</span> <span class="c1">// September</span>
<span class="nx">d</span><span class="p">.</span><span class="nx">toString</span><span class="p">();</span> <span class="c1">// October 1st!!! because there are only 30 says in September</span>

<span class="c1">// let's try this with preventOverflow...</span>
<span class="nx">d</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">XDate</span><span class="p">(</span><span class="mi">2011</span><span class="p">,</span> <span class="mi">7</span><span class="p">,</span> <span class="mi">31</span><span class="p">);</span> <span class="c1">// August 31</span>

<span class="nx">d</span><span class="p">.</span><span class="nx">setMonth</span><span class="p">(</span><span class="mi">8</span><span class="p">,</span> <span class="kc">true</span><span class="p">);</span> <span class="c1">// September</span>
<span class="nx">d</span><span class="p">.</span><span class="nx">toString</span><span class="p">();</span> <span class="c1">// September 30!</span>

</pre>
</div>


<p>Setting <code>preventOverflow</code> to <code>true</code> guarantees the date will be in desired month.
It is optional and defaults to <code>false</code>.</p>

<h2 id="Adding">Adding</h2>


<p>The following methods add or subtract time from the XDate:</p>

<dl><dt>
    .addYears(years, <i>preventOverflow</i>)
</dt>
<dt>
    .addMonths(months, <i>preventOverflow</i>)
</dt>

<dt>
    .addWeeks(weeks)
</dt>
<dt>
    .addDays(days)
</dt>
<dt>
    .addHours(hours)
</dt>
<dt>
    .addMinutes(minutes)
</dt>
<dt>

    .addSeconds(seconds)
</dt>
<dt>
    .addMilliseconds(milliseconds)
</dt>
</dl><p>If a value is negative, subtraction will occur. Values may be floating-point numbers.</p>

<p>Please note, these methods directly modify the object. Use <a href="#clone">clone</a> if you need a copy.</p>

<h2 id="Diffing">Diffing</h2>


<p>The following methods return the amount of time that must be added to the XDate in order to arrive at <code>otherDate</code>.</p>

<dl><dt>
    .diffYears(otherDate)
</dt>
<dt>
    .diffMonths(otherDate)
</dt>
<dt>
    .diffWeeks(otherDate)

</dt>
<dt>
    .diffDays(otherDate)
</dt>
<dt>
    .diffHours(otherDate)
</dt>
<dt>
    .diffMinutes(otherDate)
</dt>
<dt>
    .diffSeconds(otherDate)
</dt>

<dt>
    .diffMilliseconds(otherDate)
</dt>
</dl><p><em>otherDate</em> can be an XDate, a native Date, a milliseconds time, or a date-string.</p>

<p>The results will be positive or negative depending on the ordering of the dates:</p>

<div class="highlight"><pre><span class="kd">var</span> <span class="nx">thanksgiving</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">XDate</span><span class="p">(</span><span class="mi">2011</span><span class="p">,</span> <span class="mi">10</span><span class="p">,</span> <span class="mi">24</span><span class="p">);</span>

<span class="kd">var</span> <span class="nx">christmas</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">XDate</span><span class="p">(</span><span class="mi">2011</span><span class="p">,</span> <span class="mi">11</span><span class="p">,</span> <span class="mi">25</span><span class="p">);</span>

<span class="nx">thanksgiving</span><span class="p">.</span><span class="nx">diffDays</span><span class="p">(</span><span class="nx">christmas</span><span class="p">);</span> <span class="c1">// 31</span>
<span class="nx">christmas</span><span class="p">.</span><span class="nx">diffDays</span><span class="p">(</span><span class="nx">thanksgiving</span><span class="p">);</span> <span class="c1">// -31</span>

</pre>
</div>


<p>Also, the result can potentially be a floating-point number:</p>

<div class="highlight"><pre><span class="kd">var</span> <span class="nx">jan2011</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">XDate</span><span class="p">(</span><span class="mi">2011</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">);</span>

<span class="kd">var</span> <span class="nx">jul2012</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">XDate</span><span class="p">(</span><span class="mi">2012</span><span class="p">,</span> <span class="mi">6</span><span class="p">,</span> <span class="mi">1</span><span class="p">);</span>

<span class="nx">jan2011</span><span class="p">.</span><span class="nx">diffYears</span><span class="p">(</span><span class="nx">jul2012</span><span class="p">);</span> <span class="c1">// 1.5</span>
</pre>
</div>


<p>You'll have to do the rounding or flooring yourself.</p>

<h2 id="Parsing">Parsing</h2>


<p>Date-strings must either be in <a href="http://en.wikipedia.org/wiki/ISO_8601">ISO8601 format</a>
or <a href="http://tools.ietf.org/html/rfc3339">IETF format</a> (like "Mon Sep 05 2011 12:30:00 GMT-0700 (PDT)")</p>

<p>ISO8601 is the preferred format. Examples:</p>

<ul><li><code>"2011-09-05"</code></li>
<li><code>"2011-09-05T12:30:00"</code></li>

<li><code>"2011-09-05T12:30:00-07:00"</code></li>
<li><code>"2011-09-05T12:30:00Z"</code></li>
</ul><p>Advanced: <a href="https://gist.github.com/1221373">extending the parser</a></p>

<h2 id="Formatting">Formatting</h2>




<dl><dt>
    .toString(<i>formatString, settings</i>)

</dt>
<dd>
    If <code>formatString</code> is not specified, a browser-produced IETF string will be returned.
    <code>settings</code> can be a name of an available locale or an object that overrides the default locale's settings.
</dd>
<dt>
    .toUTCString(<i>formatString, settings</i>)
</dt>

<dd>
    Same as <code>toString</code> but gets its values from the UTC version of the date.
    As a result, "Z" will be displayed as the timezone.
</dd>
<dt>
    .toISOString()
</dt>
<dd>
    Returns an ISO8601 string that has been normalized to UTC. Will have a "Z" timezone indicator.
    See the native Date's specs for
    <a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Date/toISOString">toISOString</a>.
</dd>

<dt>
    .toDateString()
</dt>
<dd>
    Same as native Date's
    <a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Date/toDateString">toDateString</a>
</dd>
<dt>
    .toTimeString()
</dt>
<dd>
    Same as native Date's
    <a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Date/toTimeString">toTimeString</a>

</dd>
<dt>
    .toLocaleString()
</dt>
<dd>
    Same as native Date's
    <a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Date/toLocaleString">toLocaleString</a>
</dd>
<dt>
    .toLocaleDateString()
</dt>
<dd>
    Same as native Date's
    <a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Date/toLocaleDateString">toLocaleDateString</a>

</dd>
<dt>
    .toLocaleTimeString()
</dt>
<dd>
    Same as native Date's
    <a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Date/toLocaleTimeString">toLocaleTimeString</a>
</dd>
</dl><p>A <code>formatString</code> can contain any of the following tokens:</p>

<table><tr><th> fff    </th><td> milliseconds, 3-digits </td></tr><tr><th> s      </th><td> seconds </td></tr><tr><th> ss     </th><td> seconds, 2-digits </td></tr><tr><th> m      </th><td> minutes </td></tr><tr><th> mm     </th><td> minutes, 2-digits </td></tr><tr><th> h      </th><td> hours, 12-hour clock </td></tr><tr><th> hh     </th><td> hours, 12-hour clock, 2-digits </td></tr><tr><th> H      </th><td> hours, 24-hour clock </td></tr><tr><th> HH     </th><td> hours, 24-hour clock, 2-digits </td></tr><tr><th> d      </th><td> date number </td></tr><tr><th> dd     </th><td> date number, 2-digits </td></tr><tr><th> ddd    </th><td> day name, 3-characters (like "Sun") </td></tr><tr><th> dddd   </th><td> day name, full (like "Sunday") </td></tr><tr><th> M      </th><td> month number (Jan=1, Feb=2, etc) </td></tr><tr><th> MM     </th><td> month number, 2-digits </td></tr><tr><th> MMM    </th><td> month name, 3-characters (like "Jan") </td></tr><tr><th> MMMM   </th><td> month name, full (like "January") </td></tr><tr><th> yy     </th><td> year, 2-digits </td></tr><tr><th> yyyy   </th><td> year, 4-digits </td></tr><tr><th> t      </th><td> a/p </td></tr><tr><th> tt     </th><td> am/pm </td></tr><tr><th> T      </th><td> A/P </td></tr><tr><th> TT     </th><td> AM/PM </td></tr><tr><th> z      </th><td> timezone offset hour (like "-7") or "Z" </td></tr><tr><th> zz     </th><td> timezone offset hour, 2-digits (like "-07") or "Z" </td></tr><tr><th> zzz    </th><td> timezone offset hour, 2-digits, and minutes (like "-07:00") or "Z" </td></tr><tr><th> w      </th><td> ISO week number </td></tr><tr><th> ww     </th><td> ISO week number, 2 digits </td></tr><tr><th> S      </th><td> day-of-week ordinal (like "st", "nd", "rd") </td></tr><tr><th> i      </th><td> ISO8601 format, <b>without</b> a timezone indicator </td></tr><tr><th> u      </th><td> ISO8601 format, <b>with</b> a timezone indicator </td></tr></table><p>Example:</p>

<div class="highlight"><pre><span class="kd">var</span> <span class="nx">d</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">XDate</span><span class="p">(</span><span class="mi">2012</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">8</span><span class="p">);</span>

<span class="nx">d</span><span class="p">.</span><span class="nx">toString</span><span class="p">(</span><span class="s2">"MMM d, yyyy"</span><span class="p">);</span> <span class="c1">// "Jun 8, 2012"</span>
<span class="nx">d</span><span class="p">.</span><span class="nx">toString</span><span class="p">(</span><span class="s2">"i"</span><span class="p">);</span>           <span class="c1">// "2012-06-08T00:00:00"</span>

<span class="nx">d</span><span class="p">.</span><span class="nx">toString</span><span class="p">(</span><span class="s2">"u"</span><span class="p">);</span>           <span class="c1">// "2012-06-08T00:00:00-07:00"</span>
</pre>
</div>


<p>If you want to have literal text in your formatString, enclose it in single quotes:</p>

<div class="highlight"><pre><span class="kd">var</span> <span class="nx">d</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">XDate</span><span class="p">(</span><span class="mi">2012</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">8</span><span class="p">);</span>

<span class="nx">d</span><span class="p">.</span><span class="nx">toString</span><span class="p">(</span><span class="s2">"'the month is' MMMM"</span><span class="p">);</span> <span class="c1">// "the month is June"</span>
</pre>
</div>


<p>A literal single quote is represented by two consecutive single quotes.</p>

<p>If you want to output text only if certain values are non-zero, enclose your tokens in parenthesis:</p>

<div class="highlight"><pre><span class="k">new</span> <span class="nx">XDate</span><span class="p">(</span><span class="mi">2011</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">6</span><span class="p">,</span> <span class="mi">0</span><span class="p">).</span><span class="nx">toString</span><span class="p">(</span><span class="s1">'M/d/yy h(:mm)TT'</span><span class="p">);</span> <span class="c1">// "1/1/11 6AM"</span>

<span class="k">new</span> <span class="nx">XDate</span><span class="p">(</span><span class="mi">2011</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">6</span><span class="p">,</span> <span class="mi">30</span><span class="p">).</span><span class="nx">toString</span><span class="p">(</span><span class="s1">'M/d/yy h(:mm)TT'</span><span class="p">);</span> <span class="c1">// "1/1/11 6:30AM"</span>

</pre>
</div>


<p>Advanced:</p>

<ul><li><a href="https://gist.github.com/1221376">changing locale</a></li>
<li><a href="https://gist.github.com/1221379">extending the formatter</a></li>
</ul><h2 id="UTC_Methods">UTC Methods</h2>


<p>The following methods are similar to previously mentioned methods but operate on the UTC values of the date:</p>

<dl><dt>.getUTCFullYear()</dt>
<dt>.getUTCMonth()</dt>
<dt>.getUTCWeek()</dt>
<dt>.getUTCDate()</dt>
<dt>.getUTCDay()</dt>
<dt>.getUTCHours()</dt>
<dt>.getUTCMinutes()</dt>
<dt>.getUTCSeconds()</dt>

<dt>.getUTCMilliseconds()</dt>
<dt>.setUTCFullYear(year)</dt>
<dt>.setUTCMonth(month)</dt>
<dt>.setUTCDate(date)</dt>
<dt>.setUTCHours(hours)</dt>
<dt>.setUTCMinutes(minutes)</dt>
<dt>.setUTCSeconds(seconds)</dt>
<dt>.setUTCMilliseconds(milliseconds)</dt>
</dl><h2 id="UTC_Mode">UTC Mode</h2>


<p>Just like a native Date, an XDate is represented by its number of milliseconds since the epoch.
Also like a native Date, methods like <code>getDate</code> and <code>getHours</code> are dependant upon the client computer's timezone.</p>

<p>However, you can remove this reliance on the client computer's timezone and make a UTC date, a date without a timezone.
A date in UTC-mode will have all of its "get" methods identical to its "getUTC" methods and
won't experience any daylight-savings time.</p>

<p>A <code>true</code> argument can be appended to any of the <a href="#Constructors">constructors</a> to make an XDate
in UTC-mode:</p>

<div class="highlight"><pre><span class="nx">d</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">XDate</span><span class="p">(</span><span class="kc">true</span><span class="p">);</span> <span class="c1">// the current date, in UTC-mode</span>
<span class="nx">d</span><span class="p">.</span><span class="nx">toString</span><span class="p">();</span> <span class="c1">// "Mon, 24 Oct 2011 08:42:08 GMT"</span>

<span class="nx">d</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">XDate</span><span class="p">(</span><span class="mi">2012</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">8</span><span class="p">,</span> <span class="kc">true</span><span class="p">);</span> <span class="c1">// values will be interpreted as UTC</span>

<span class="nx">d</span><span class="p">.</span><span class="nx">toString</span><span class="p">();</span> <span class="c1">// "Fri, 08 Jun 2012 00:00:00 GMT"</span>

<span class="nx">d</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">XDate</span><span class="p">(</span><span class="s1">'2012-06-08'</span><span class="p">,</span> <span class="kc">true</span><span class="p">);</span> <span class="c1">// ambiguous timezone, so will be parsed as UTC</span>

<span class="nx">d</span><span class="p">.</span><span class="nx">toString</span><span class="p">();</span> <span class="c1">// "Fri, 08 Jun 2012 00:00:00 GMT"</span>
</pre>
</div>


<p>Here are methods that relate to UTC-mode:</p>

<dl><dt>

    .getUTCMode()
</dt>
<dd>
    Returns <code>true</code> if the date is in UTC-mode and <code>false</code> otherwise
</dd>
<dt>
    .setUTCMode(utcMode, <i>doCoercion</i>)

</dt>
<dd>
    <code>utcMode</code> must be either <code>true</code> or <code>false</code>.
    If the optional <code>doCoercion</code> parameters is set to <code>true</code>, the underlying millisecond time
    of the date will be coerced in such a way that methods like <code>getDate</code> and <code>getHours</code> will
    have the same values before and after the conversion.

</dd>
<dt>
    .getTimezoneOffset()
</dt>
<dd>
    Returns the number of minutes from UTC, just like the native Date's
    <a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Date/getTimezoneOffset">getTimezoneOffset</a>.
    However, if the XDate is in UTC-mode, <code>0</code> will be returned.
</dd>
</dl><p>Please note, these methods directly modify the object. Use <a href="#clone">clone</a> if you need a copy.</p>

<h2 id="Utilities">Utilities</h2>




<dl><dt id="clone">
    .clone()
</dt>
<dd>
    returns a copy of the XDate
</dd>
<dt>
    .clearTime()

</dt>
<dd>
    sets the hours, minutes, seconds, and milliseconds to zero
</dd>
<dt>
    .valid()
</dt>
<dd>
    return <code>true</code> if the XDate is a valid date, <code>false</code> otherwise

</dd>
<dt>
    .toDate()
</dt>
<dd>
    Returns a conversion to a native
    <a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Date">Date</a>
</dd>
</dl><p>The following utilities are members of the XDate class and are not associated with a specific XDate instance:</p>

<dl><dt>
    XDate.getDaysInMonth(year, month)

</dt>
<dd>
    Returns the number of days in the given month
</dd>
<dt>
    XDate.parse(dateString)
</dt>
<dd>
    Parses a date-string and returns milliseconds since the epoch.
    You'll probably want to use <code>new XDate(dateString)</code> instead.
</dd>
<dt>

    XDate.now()
</dt>
<dd>
    Returns the current date, as milliseconds since the epoch.
    You'll probably want to use <code>new XDate()</code> instead.
</dd>
<dt>
    XDate.today()
</dt>
<dd>
    Returns the current date with time cleared, as an XDate object

</dd>
<dt>
    XDate.UTC(year, month, <i>date, hours, minutes, seconds, milliseconds</i>)
</dt>
<dd>
    Returns a milliseconds time since the epoch for the given UTC date
</dd>
</dl><h2 id="Chaining">Chaining</h2>


<p>Many of XDate's methods return a reference to the same XDate object. This allows you to "chain"
operations together and makes for more concise code:</p>

<div class="highlight"><pre><span class="nx">d1</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">XDate</span><span class="p">();</span>
<span class="nx">d2</span> <span class="o">=</span> <span class="nx">d1</span><span class="p">.</span><span class="nx">clone</span><span class="p">()</span>

       <span class="p">.</span><span class="nx">setUTCMode</span><span class="p">(</span><span class="kc">true</span><span class="p">)</span>
       <span class="p">.</span><span class="nx">setDate</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
       <span class="p">.</span><span class="nx">addMonths</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>

       <span class="p">.</span><span class="nx">addYears</span><span class="p">(</span><span class="mi">2</span><span class="p">);</span>
</pre>
</div>


<h2 id="Inconsistencies">Inconsistencies with Native Date</h2>


<p>XDate attempts to be "backwards-compatible" with the native Date object.
However, there are two small departures that were made:</p>

<p>If you've never noticed, a native Date object returns it's millisecond value every time there is a "set" method.
This is not very helpful. In the same situations, an XDate will return a reference to itself to allow for chaining.
This is much more useful, but does not match the way the native Date works.</p>

<p>Also, when a native Date is concatenated with a string (with the <code>+</code> operator), the object will produce a date-string.
However, this behavior was impossible to emulate with XDate, so please always explicitly use <code>toString</code> before
concatenating with a string:</p>

<div class="highlight"><pre><span class="kd">var</span> <span class="nx">nativeDate</span> <span class="o">=</span> <span class="k">new</span> <span class="nb">Date</span><span class="p">();</span>

<span class="nx">alert</span><span class="p">(</span><span class="s2">"my date: "</span> <span class="o">+</span> <span class="nx">nativeDate</span><span class="p">);</span> <span class="c1">// "my date: Mon Sep 05 2011 13:12:23 GMT-0700 (PDT)"</span>

<span class="kd">var</span> <span class="nx">xdate</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">XDate</span><span class="p">();</span>

<span class="nx">alert</span><span class="p">(</span><span class="s2">"my date: "</span> <span class="o">+</span> <span class="nx">xdate</span><span class="p">);</span> <span class="c1">// "my date: 1315253543319"  &lt;-- probably not what you wanted!</span>
<span class="nx">alert</span><span class="p">(</span><span class="s2">"my date: "</span> <span class="o">+</span> <span class="nx">xdate</span><span class="p">.</span><span class="nx">toString</span><span class="p">());</span> <span class="c1">// "my date: Mon Sep 05 2011 13:12:23 GMT-0700 (PDT)"</span>

</pre>
</div>


<h2 id="Deprecated">Deprecated</h2>


<p>The following methods are available, but please don't use them:</p>

<dl><dt>.getYear()</dt>
<dt>.setYear(twoDigitYear)</dt>
</dl>

<div id='bottom'>
<a class='wiki-link' href='https://github.com/arshaw/xdate/wiki'>Edit the documentation</a>
<span class='copy'>&copy; 2011 <a href='http://arshaw.com/'>Adam Shaw</a></span>
</div>

</div>

</body>
</html>